;;;; cl-ana is a Common Lisp data analysis library.
;;;; Copyright 2013-2015 Gary Hollis
;;;;
;;;; This file is part of cl-ana.
;;;;
;;;; cl-ana is free software: you can redistribute it and/or modify it
;;;; under the terms of the GNU General Public License as published by
;;;; the Free Software Foundation, either version 3 of the License, or
;;;; (at your option) any later version.
;;;;
;;;; cl-ana is distributed in the hope that it will be useful, but
;;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;;;; General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU General Public License
;;;; along with cl-ana.  If not, see <http://www.gnu.org/licenses/>.
;;;;
;;;; You may contact Gary Hollis (me!) via email at
;;;; ghollisjr@gmail.com

(in-package :cl-ana.file-utils)

(defun sha1 (string)
  "Returns the sha1 sum of a string of text."
  (with-input-from-string
      (str
       (with-output-to-string (s)
         (with-input-from-string (text string)
           (run "sha1sum"
                (list "-")
                :input text
                :output s))))
    (first (split-sequence #\space
                           (read-line str)))))

(defun sha1-from-pathname (pathname-or-string)
  "Returns sha1 sum of file located at pathname-or-string."
  (with-input-from-string
      (str
       (with-output-to-string (s)
         (run "sha1sum"
              (list (namestring pathname-or-string))
              :output s)))
    (first (split-sequence #\space
                           (read-line str)))))
